package com.hfdg.organization.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfdg.prototype.base.utils.TimeUtils;
import com.hfdg.organization.mapper.PositionMapper;
import com.hfdg.organization.entity.Position;
import com.hfdg.organization.service.PositionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * @ClassName PositionServiceImpl
 * @Description TODO
 * @Author yuelh
 * @Date 2019/1/19 18:26
 * @Version 1.0
 * @Company 会飞的锅工作室
 **/
@Service
public class PositionServiceImpl implements PositionService {
    @Autowired
    PositionMapper positionMapper;

    @Override
    public String insert(Position position) {
        String uid = UUID.randomUUID().toString();
        position.setUid(uid);
        position.setDelFlag("0");
        position.setCreateTime(new Date());
        positionMapper.insert(position);
        return uid;
    }

    @Override
    public Integer update(Position position) {
        position.setUpdateTime(new Date());
        return positionMapper.update(position);
    }

    @Override
    public Integer  delete(String uid) {
        return positionMapper.delete(uid);
    }
    @Override
    public Integer batchDelete(String[] uids) {
            return positionMapper.batchDelete(uids);
    }

    @Override
    public Position get(String uid) {
        return positionMapper.get(uid);
    }

    @Override
    public List<Position> list(Position position) {
    return  positionMapper.list(position);
    }

    @Override
    public PageInfo<Position> getPagingData(int offset, int limit,String orderBy, Position position) {
        if(null==orderBy|| StringUtils.isBlank(orderBy)){
        PageHelper.startPage((offset/limit)+1,limit);
        }else{
        PageHelper.startPage((offset/limit)+1,limit,orderBy);
        }
        PageInfo<Position> pageInfo =new PageInfo<>(positionMapper.list(position));
            return pageInfo;
            }
    @Override
    public String insertOrUpdate(Position position){
        if(null!=position.getUid()){
            this.update(position);
        }else{
            this.insert(position);
        }
        return position.getUid();
    }
            }
